<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String ctx = request.getContextPath();
    request.setAttribute("ctx", ctx);
%>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.8.2.min.js"></script>
    <script >
        function fenye(cpage){
            $("[name='cpage']").val(cpage)
            $("form").submit();
        }
        function toadd(){
            location="toadd.do";
        }

        // 就绪函数
        $(function (){
            $.post(
                "cityList.do",
                {"pid":0},
                function (obj){
                   for(var i in obj){
                       //回显
                       if("${map.sheng}"==obj[i].id){
                           $("[name='sheng']").append(" <option value="+obj[i].id+" selected>"+obj[i].name+"</option>")
                           $("[name='sheng']").trigger("change");
                       }else{
                           $("[name='sheng']").append(" <option value="+obj[i].id+">"+obj[i].name+"</option>")
                       }

                   }
                },"json");

            $("[name='sheng']").change(function (){
                var pid=$(this).val();
                $("[name='shi']").empty();
                $("[name='shi']").append("<option value=''>请选择</option>");
                $("[name='xian']").empty();
                $("[name='xian']").append("<option value=''>请选择</option>");
                $.post(
                    "cityList.do",
                    {"pid":pid},
                    function (obj){
                        for(var i in obj){
                            if("${map.shi}"==obj[i].id){
                                //回显
                                $("[name='shi']").append(" <option value="+obj[i].id+" selected>"+obj[i].name+"</option>")
                                $("[name='shi']").trigger("change");
                            }else{
                                //回显
                                $("[name='shi']").append(" <option value="+obj[i].id+">"+obj[i].name+"</option>")
                            }

                        }
                    },"json");
            })

            $("[name='shi']").change(function (){
                var pid=$(this).val();
                $("[name='xian']").empty();
                $("[name='xian']").append("<option value=''>请选择</option>");
                $.post(
                    "cityList.do",
                    {"pid":pid},
                    function (obj){
                        for(var i in obj){
                            if("${map.xian}"==obj[i].id){
                                //回显
                                $("[name='xian']").append(" <option value="+obj[i].id+" selected>"+obj[i].name+"</option>")
                            }else{
                                //回显
                                $("[name='xian']").append(" <option value="+obj[i].id+">"+obj[i].name+"</option>")
                            }


                        }
                    },"json");
            })
        })

        function del(sid){
            $.ajax({
                url:"del.do",
                data:{"sid":sid},
                type:'post',
                dataType:"json",
                success:function (obj){
                   if(obj>0){
                       location="list.do";
                   }
                }
            })
        }

        $(function (){
            $("[name='checkAll']").change(function (){
                var flag=$(this).prop("checked");
                $("[name='checkOne']").prop("checked",flag);
            })
        })
        function fx(){
            $("[name='checkOne']").each(function (){
                $(this).prop("checked",!$(this).prop("checked"))
            })
        }
        function dels(){
            var sids="";
            $("[name='checkOne']:checked").each(function (){
                sids+=","+$(this).val();
            })
            sids=sids.substr(1);
            $.ajax({
                url:"dels.do",
                data:{"sids":sids},
                type:'post',
                dataType:"json",
                success:function (obj){
                    if(obj>0){
                        location="list.do";
                    }
                }
            })
        }

        function toupd(sid){
            location="toupd.do?sid="+sid;
        }
        function logout(){
            location="logout.do";
        }
    </script>
</head>
<body>
    <marquee>
        <h1>登陆成功，欢迎${user.uname}光临本系统</h1>
    </marquee>
    <input type="button" value="注销" onclick="logout()">
    <form method="post" action="list.do">
            <input type="hidden" name="cpage">
        姓名:<input type="text" name="mohu1" value="${map.mohu1}">
        生日:<input type="text" name="startTime" value="${map.startTime}">
        ----
        <input type="text" name="endTime" value="${map.endTime}"><br>
        性别:<input type="radio" value="男" name="sex" ${map.sex=='男'?'checked':''} >男
        <input type="radio"  name="sex"  value="女" ${map.sex=='女'?'checked':''} >女<BR>
        省：<SELECT name="sheng">
                <option value="">请选择</option>
            </SELECT>
        市：<SELECT name="shi">
                <option value="">请选择</option>
            </SELECT>
        县：<SELECT name="xian">
                <option value="">请选择</option>
            </SELECT>
        <input type="submit">
    </form>
<table>
   <tr>
       <td>
           <input type="checkbox" name="checkAll">
       </td>
       <td>编号</td>
       <td>姓名</td>
       <td>头像</td>
       <td>性别</td>
       <td>爱好</td>
       <td>生日</td>
       <td>籍贯</td>
       <td>科目</td>
       <td>

           <input type="button" value="添加" onclick="toadd()">
       </td>
   </tr>
    <c:forEach items="${pageInfo.list}"  var="m">
        <tr>
            <td>
                <input type="checkbox" name="checkOne" value="${m.sid}">
            </td>
            <td>${m.sid}</td>
            <td>${m.sname}</td>
            <td>
                <img src="${m.pic}" width="50px">
            </td>
            <td>${m.sex}</td>
            <td>${m.hobby}</td>
            <td>${m.birthday}</td>
            <td>${m.shengName}--${m.shiName}--${m.xianName}</td>
            <td>${m.cnames}</td>
            <td>
                <input type="button" value="修改" onclick="toupd(${m.sid})">
                <input type="button" value="删除" onclick="del(${m.sid})">

            </td>
        </tr>
    </c:forEach>

    <tr>
        <td colspan="11">
<%--            <input type="button" value="首页"  onclick="fenye(1)">--%>
<%--            <input type="button" value="上一页"  onclick="fenye(${pageInfo.isFirstPage?1:pageInfo.prePage})">--%>
<%--            <input type="button" value="下一页"  onclick="fenye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">--%>
<%--            <input type="button" value="尾页"  onclick="fenye(${pageInfo.pages})">--%>

            <a href="javaScript:fenye(1)">首页</a>
            <a href="javaScript:fenye(${pageInfo.isFirstPage?1:pageInfo.prePage})">上一页</a>
            <c:forEach items="${pageInfo.navigatepageNums}" var="index">
                <a href="javaScript:fenye(${index})">${index}</a>
            </c:forEach>
            <a href="javaScript:fenye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下一页</a>
            <a href="javaScript:fenye(${pageInfo.pages})">尾页</a>
            <input type="button" value="反选" onclick="fx()">
            <input type="button" value="批量删除" onclick="dels()">
        </td>

    </tr>
</table>
</body>
</html>
